<?php
  // Use "Helper" Elfinder (in views/helpers)
  // Does the javascript and css link importing for all required client files to run Elfinder file explorer
  //$this->Elfinder->importElfinder(/*inline: */ false);
  $options = array('inline'=>false);
  //echo $this->Html->css("menu_tight",null,$options);
  echo $this->Html->css("menu_tight_vertical",null,$options);
?>

<div class="jobs index panel">
	<h2><?php __('Jobs');?></h2>
  
  <?php if ($jobs):?>	
  <table class="panel">
    <thead>
      <tr>
        <!-- TABLE HEADERS  -->
        <th></th>

        <th class="jobGroup"><?php echo $this->Paginator->sort('Group','JobGroup.name');?></th>
        
        <th class="jobName"><?php echo $this->Paginator->sort('Job Name','name');?></th>

        <th class="altJobName">
          <?php echo $this->Paginator->sort('Alternate Name', 'JobAltName.name');?>
        </th>

        <th class="description">
          <?php echo $this->Paginator->sort('Description', 'Description.content');?>
        </th>

        <th class="createdDate"><?php echo $this->Paginator->sort('created');?></th>
        <!-- <th><?php echo $this->Paginator->sort('modified');?></th> -->
      </tr>
    </thead>
    <tbody>
      <?php
      //////////////////////////////////////////////////////////////////////
      //// List all Jobs ///////////////////////////////////////////////////
      $i = 0;
      foreach ($jobs as $job):
        $class = null;
        if ($i++ % 2 == 0) {
          $class = ' class="altrow"';
        }
      ?>
      <tr<?php echo $class;?>>
        <td>
          <?php //echo $job['Job']['id']; ?>
          <ul class="menuTightVert shadow3">
          <?php
          // define some empty vars for passing to method for code readability (rather than passing 'null')
          $linkArgs     = null;  $separateArgs = null;   $subList = null;  $confirmMsg = null;
          $linkOptions = array();   $imgOptions =  array('class'=>'icon'); 

          // "Edit Job" menu item
          $isFirstTopMenuItem = true; $isLastTopMenuItem  = false;
          $linkDisplayStr = '';   $tooltip = 'Edit Job';
          $iconPath = 'Icons/White/NoCircle/32x32/pencil.png'; 
          $linkToController = 'jobs';         $linkToMethod = 'form';
          $linkArgs = array($job['Job']['id'], /* template_version_id: */ "dummy", // Can't use null
                                               /* edit_job_id: */ $job['Job']['id']);
          $separateArgs = true; // pass the args as separate args to the method (rather than all as one array)
          echo $this->Menu->makeListItem($linkToController, $linkToMethod, $linkArgs, $separateArgs,
                                $isFirstTopMenuItem,$isLastTopMenuItem, $linkDisplayStr, $tooltip, 
                                $iconPath, $subList, $linkOptions, $imgOptions, $confirmMsg );

          // "Delete" menu item
          $isFirstTopMenuItem = false; $isLastTopMenuItem  = true;
          $linkDisplayStr = ''; $tooltip = 'Delete Job and all its Job Versions';
          $iconPath = 'Icons/White/NoCircle/32x32/trash.png'; 
          $linkToController = 'jobs';         $linkToMethod = 'delete';
          $linkArgs = array($job['Job']['id']);
          $separateArgs = true; // pass the args as separate args to the method (rather than all as one array)
          $confirmMsg = "Are you sure you want to delete Job '{$job['Job']['name']}' AND all its Versions?";
          echo $this->Menu->makeListItem($linkToController, $linkToMethod, $linkArgs, $separateArgs,
                                $isFirstTopMenuItem,$isLastTopMenuItem, $linkDisplayStr, $tooltip, 
                                $iconPath, $subList, $linkOptions, $imgOptions, $confirmMsg ); 
          ?>
          </ul>
        
        </td>
        
        <!-- <td class="jobGroup"><?php echo $job['JobGroup']['name']; ?>&nbsp;</td>-->
        <td class="jobGroupName">
          <?php
            $tooltipStr = "View a list of Jobs for just this Job Group";
            $options = array('title'=>$tooltipStr);
            echo $this->Html->link($job['JobGroup']['name'], 
                    array('controller'=>'jobs' ,'action' => 'indexByGroupId', $job['Job']['job_group_id']),
                    $options); ?>
        </td>

        <td class="jobName">
          <?php 
           $tooltipStr = "View Job Versions for this Job";
           $options = array('title'=>$tooltipStr);
           echo $this->Html->link($job['Job']['name'], array('action' => 'view', $job['Job']['id']), $options); ?>
        </td>

        <td><?php echo $job['JobAltName']['name'] ?>&nbsp;</td>
        <td><?php echo $job['Description']['content'] ?>&nbsp;</td>
        <td><?php echo $job['Job']['created']; ?>&nbsp;</td>
        <!-- <td><?php echo $job['Job']['modified']; ?>&nbsp;</td> -->
      </tr>
      <?php endforeach; ?>
    </tbody>
	</table>
  
  
	<!-- Begin Paging stuff ------------------------------------------------------------ -->
  <p>
    <?php
    echo $this->Paginator->counter(array(
    'format' => __('Page %page% of %pages%, showing %current% records out of %count% total', true)
    ));
    ?>
  </p>
     <!-- "<< previous || next >>" -->
	<div class="paging">
		<?php echo $this->Paginator->prev('<< ' . 'previous', array(), null, array('class'=>'disabled'));?>
	  | 	<?php echo $this->Paginator->numbers();?>
    |
		<?php echo $this->Paginator->next('next' . ' >>',     array(), null, array('class'=>'disabled'));?>
	</div>

  <?php else:?>
  <p>There are currently no records to display.  
    <?php echo $this->Html->link('Add one now', array('action' => 'form')); ?>
  </p>
  <?php endif; ?>  
</div> <!-- end 'jobs index' div -->
<!-- end Paging stuff ------------------------------------------------------------ -->



<!--
<h3 id="info">Elfinder and ImageJ are below (but may be hidden)</h3>
<button id="showElfinderAndImageJBtn" title="Hide Applet">Show 'em</button>


<!--  ELFINDER -------------------------------------------------- -->
<!--
<form id="elfinder_form">
  <input type="button" value="Show File Explorer"/>
</form>

<div id="file_exp">
</div>
-->
<!-- end ELFINDER -----------------------------------------  -->

<!-- -------- FIJI ----------------------------------------  -->
<?php
// Globals class is now being imported in bootstrap.php
//App::import('Lib', 'headless_fiji_macro_executer');
//
//// <editor-fold defaultstate="collapsed" desc="Prepare images (stacks) for Fiji">
//$debug = false;
//// Get a new Strategy obj to handle calling the macro
//$macExec = new HeadlessFijiMacroExecuter(/* debug: */ $debug);
///////////////////////////////////////////////////
///////// FITS MACRO  /////////////////////////////
//$macExec->set_macro_name("CreateStack_Resample_from_FITS.ijm");
//// Linux
//if (GlobalsClass::getPlatform() == PlatformType::linux) {
//  $src_img_path = GlobalsClass::getImagesPath() . "Samples/";
//  $result_img_path = GlobalsClass::getImagesPath() . "Samples/";
//}
//// Windows
//else if (GlobalsClass::getPlatform() == PlatformType::windows) {
//  $src_img_path = GlobalsClass::getImagesPath() . "Samples\\";
//  $result_img_path = GlobalsClass::getImagesPath() . "Samples\\";
//}
//
//$result_img_name = "stack_from_resampled_FITS.zip";
//$FITS_stack_with_rel_path = GlobalsClass::getImgPathRelToApplet()
//                            . "Samples/$result_img_name"; // used in html                                                        
//$scale = 2;
//
//$args_array = array(/* debug: */ $debug, $src_img_path, $result_img_path,
//                     $result_img_name, $scale);
//
//$args_str = $macExec->construct_macro_str($args_array, GlobalsClass::getMacroArgDelim());
//
//$macExec->set_macro_arg_str($args_str);
//$macExec->execute_macro(); // creates the stack
//  
///////////////////////////////////////////////////
///////// RAW MACRO  //////////////////////////////
//$macExec->set_macro_name("Convert_F32_to_Tiff.ijm");
//// Linux
//if (GlobalsClass::getPlatform() == PlatformType::linux) {
//  $src_img_path = GlobalsClass::getImagesPath() . "Samples/";
//  $result_img_path = GlobalsClass::getImagesPath() . "Samples/";
//}
//// Windows
//else if (GlobalsClass::getPlatform() == PlatformType::windows) {
//  $src_img_path = GlobalsClass::getImagesPath() . "Samples\\";
//  $result_img_path = GlobalsClass::getImagesPath() . "Samples\\";
//}
//$result_img_name = "stack_from_converted_RAW.zip";
//
//$RAW_stack_with_rel_path = GlobalsClass::getImgPathRelToApplet()
//                           . "Samples/$result_img_name"; // used in html                                                        
//$scale = 2; // 2 means scale to 1/2
//$rawImgType = "32-bit Real";
//$rawWidth = 560;
//$rawHeight = 560;
////$rawWidth   = 1024;
////$rawHeight  = 768;
//$rawOffset = 0;
//$rawNumImgs = 1;
//$rawGapBetweenImgs = 0;
/////// CONSTRUCT THE RAW MACRO ARGUMENT ///
//$args_array = array($debug, $src_img_path, $result_img_path, $result_img_name, $scale,
//                    $rawImgType, $rawWidth, $rawHeight, $rawOffset,
//                    $rawNumImgs, $rawGapBetweenImgs); // order of args matters!
//
//$args_str = $macExec->construct_macro_str($args_array, GlobalsClass::getMacroArgDelim());
//$macExec->set_macro_arg_str($args_str);
//$macExec->execute_macro(); // creates the stack   // </editor-fold>
 
?>
<!--
<h4 id="imageJH4">ImageJ embedded in the website:</h4> 

<button id="hideAppletBtn" title="Hide Applet">Remove ImageJ</button>

<div id="applet_div">

      <applet 
          id="applet"
          codebase=<?="\"". '' /*GlobalsClass::getFijiSignedAppletFullPath()*/ ."\"" ?>
          code="ij.ImageJApplet.class" archive="ImageJA.jar"
          width="100%" height="100%" 
          security="all-permissions">         
          <!--  ImageJA version "ij-1.45h.jar" new as of May 2011 
                Note that we must use the ImageJA version, not plain ImageJ
                to get the fully embedded version (embedded in the webpage).
          -->
    <!--  
    <param name="url1" value="../../Images/Desert.jpg" />
    -->
 <!--
    <param name="url1" value=<?="\"$FITS_stack_with_rel_path\""?>/>
    <param name="url2" value=<?="\"$RAW_stack_with_rel_path\""?>/>

    <param name="eval1" value='run("Brightness/Contrast..."); 
                               run("Enhance Contrast", "saturated=0.35");
                               run("Put Behind [tab]");
                               run("Next Slice [>]");
                               run("Enhance Contrast", "saturated=0.35");
                               '/>  
  </applet>
</div>
-->
<!-- -------- end FIJI ------------------------------------  -->